<?php

/**
 *TrainerCity 商品类型管理程序 *
 
 * $Id: goods_type.php 17063 2010-03-25 06:35:46Z  $
*/

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

$exc = new exchange($ecs->table("goods_type"), $db, 'cat_id', 'cat_name');

/*------------------------------------------------------ */
//-- Manage UI
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'manage')
{
    #assign_query_info();

    $smarty->assign('ur_here',          $_LANG['08_goods_type']);
    $smarty->assign('full_page',        1);

	#add by wanglei
	$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('trainertype');
	$trainertype=$db->getAll($sql);
	$smarty->assign('trainer_type_arr',   $trainertype);
	#end by wanglei
	$smarty->assign('action_link',      array('text' => 'Add New Type', 'href' => 'trainer_type.php?act=add'));

    $smarty->display('trainer_type.htm');
}

/*------------------------------------------------------ */
//-- Add New Type
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'add_newtype')
{
	 $new_type = !empty($_POST['new_type']) ? trim($_POST['new_type']) : '';
	 
	if($new_type)
	{
		/*Insert*/	
		$sql = "INSERT INTO " . $ecs->table('trainertype') . "(trainerType) VALUES ('" . $new_type . "')";
    	if($db->query($sql) != false)
		{
			/*Add Successfully*/	
			$links = array(array('href' => 'trainer_type.php?act=manage', 'text' => "Trainer Type List"));
        	sys_msg("New Type Add Successfully!", 0, $links);
		}
		else
		{
			/*Add Failed*/	
			$links = array(array('href' => 'trainer_type.php?act=manage', 'text' => "Trainer Type List"));
        	sys_msg("Failed, please try again!", 0, $links);
		}
	}
	else
	{
		/*No new type*/	
			$links = array(array('href' => 'trainer_type.php?act=manage', 'text' => "Trainer Type List"));
        	sys_msg("Please input new type!", 0, $links);
	}
}

/*------------------------------------------------------ */
//-- Modify Type
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'modify')
{
	$cat_id = !empty($_GET['cat_id']) ? intval($_GET['cat_id']) : '';
	
	#add by wanglei
	$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('trainertype')." WHERE num='$cat_id' ";
	$trainertype=$db->getRow($sql);
	
	$smarty->assign('trainer_type',   $trainertype);
	#end by wanglei
	$smarty->assign('action_link',      array('text' => 'Add New Type', 'href' => 'trainer_type.php?act=add'));

    $smarty->display('trainer_type_add.htm');
}

/*------------------------------------------------------ */
//-- Modify Type
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'act_modify')
{
	$cat_id = !empty($_POST['trainer_type_num']) ? intval($_POST['trainer_type_num']) : '';
	$trainer_type = !empty($_POST['trainer_type']) ? trim($_POST['trainer_type']) : '';
	
	if($cat_id && $trainer_type)
	{
		#add by wanglei
		$sql = "UPDATE " . $GLOBALS['ecs']->table('trainertype') .
            " SET num='$cat_id', trainerType='$trainer_type' WHERE num='$cat_id' ";
		#$GLOBALS['db']->query($sql);
		$db->query($sql);
		if($db->query($sql) != false)
		{
			/*Modify Successfully*/	
			$links = array(array('href' => 'trainer_type.php?act=manage', 'text' => "Trainer Type List"));
        	sys_msg("Modify Type Successfully!", 0, $links);
			
		}
		else
		{
			/*Modify Failed*/	
			$links = array(array('href' => 'trainer_type.php?act=manage', 'text' => "Trainer Type List"));
        	sys_msg("Failed, please try again!", 0, $links);
		}
	}
	else
	{
			/*Modify Failed*/	
			$links = array(array('href' => 'trainer_type.php?act=manage', 'text' => "Trainer Type List"));
        	sys_msg("Please input the num and tyep!", 0, $links);
	}
	
}

/*------------------------------------------------------ */
//-- Modify Type
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'delete')
{
	$cat_id = !empty($_GET['cat_id']) ? intval($_GET['cat_id']) : '';
		
	#add by wanglei
	$sql = "DELETE FROM " . $GLOBALS['ecs']->table('trainertype') .
            " WHERE num='$cat_id' ";
	#$GLOBALS['db']->query($sql);
	
	$db->query($sql);
	if($db->query($sql) != false)
	{
		/*Modify Successfully*/	
		$links = array(array('href' => 'trainer_type.php?act=manage', 'text' => "Trainer Type List"));
        sys_msg("Delete Type Successfully!", 0, $links);
			
	}
	else
	{
		/*Modify Failed*/	
		$links = array(array('href' => 'trainer_type.php?act=manage', 'text' => "Trainer Type List"));
        sys_msg("Failed, please try again!", 0, $links);
	}	
}

?>
